package org.c41.graphics.effect;

import org.c41.graphics.C41Graphic;
import org.c41.util.Check;

public class FadeIn extends AlphaEffect {

	private final long smooth;
	private final long during_time;
	
	public FadeIn(Paintable base, long time){
		super(base);
		Check.greater(time, 0L);
		
		if(time<100L){
			time=100L;
		}
		this.during_time=time;
		if(this.during_time<=1000L){
			this.smooth=100L;
		}
		else {
			this.smooth=500L;
		}
	}
	
	@Override
	public void paintReady(C41Graphic g) {
		// no painting
	}
	
	@Override
	protected float updateAlpha(long current) {
		if(current>during_time){
			complete();
			return 1.0f;
		}
		long frames = this.during_time/smooth;
		long index= current%this.during_time/frames;
		float alpha=1.0f/smooth*index;
		if(alpha>1.0f){
			alpha=1.0f;
		}
		return alpha;
	}

}
